<div class="content">
    <div id="example_title">
        <h1>Events</h1>
        All important events are supported. In the example below I added an event listener for all events. You can see what events
        are being sent in JavaScript console.
    </div>
    <div id="example_view"></div>
    <div id="example_code"></div>
</div>

<!--CODE-->
<div id="sidebar" style="height: 300px; width: 200px; float: left"></div>
<div style="margin-left: 220px;">
    <span id="event"></span>
</div>
<div style="clear: both"/>

<!--CODE-->
<script type="module">
import { w2sidebar, query } from '__W2UI_PATH__'

let sidebar = new w2sidebar({
    box: '#sidebar',
    name: 'sidebar',
    nodes: [
        { id: 'level-1', text: 'Level 1', img: 'icon-folder', expanded: true, group: true,
            nodes: [
                { id: 'level-1-1', text: 'Level 1.1', icon: 'fa fa-home' },
                { id: 'level-1-2', text: 'Level 1.2', icon: 'fa fa-comment-o' },
                { id: 'level-1-3', text: 'Level 1.3', icon: 'fa fa-coffee' }
            ]
        },
        { id: 'level-2', text: 'Level 2', img: 'icon-folder', group: true,
            nodes: [
                { id: 'level-2-1', text: 'Level 2.1', icon: 'fa fa-star-o' },
                { id: 'level-2-2', text: 'Level 2.2', icon: 'fa fa-star-o' },
                { id: 'level-2-3', text: 'Level 2.3', icon: 'fa fa-star-o' }
            ]
        }
    ]
})

sidebar.on('*', function (event) {
    query('#event').html('<span style="color: #999">Event</span>: ' + event.type + ' &nbsp;&nbsp;&nbsp;<span style="color: #999">Target</span>: ' + event.target);
    console.log('Last Event: ' + event.type + ' Target: ' + event.target);
    console.log(event);
})
</script>
